<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>系统后台 - <?php echo (C("INTENDANT_NAME")); ?> - by HemaCMS</title>
    <link href="/Public/intendant/css/admin_style.css" rel="stylesheet" />
    <script src="/Public/common/js/jquery.js"></script>
    <script src="/Public/common/js/jquery.cookie.js"></script>
    <script src="/Public/common/js/layer/layer.js"></script>
    <script src="/Public/intendant/js/iteny.intendant.js"></script> <!-- 公共easyui JS -->
    <link href="/Public/intendant/css/iteny.css" rel="stylesheet" />
    <style type="text/css">
    tr{border-left: 1px solid #e5e3e3;}
    td{border-right: 1px solid #e5e3e3;}
    </style>
</head>
<body>
<div class="wrap J_check_wrap">
   	<div class="nav">
  	    <ul class="cc">
  	        <li class="current"><a href="<?php echo U('Site/database');?>/type/export">数据备份</a></li>
  	        <li><a href="<?php echo U('Site/dataBase');?>/type/import">还原数据</a></li>
  	    </ul>
  	</div>
    <form id="export-form" action="<?php echo U('Site/export');?>" method="post">
      <div class="table_list">
        <table width="100%">
          <colgroup>
          <col width="40">
          <col width="40">
          <col width="270">
          <col width="170">
          <!-- <col width="100">
          <col width="50"> -->
          <col width="80">
          <col width="160">
          </colgroup>
          <thead>
            <tr>
              <td width="40" align="center"><input class="check-all" checked="chedked" type="checkbox" value=""</td>
              <td width="200" align="center">表名</td>
              <td width="80" align="center">表用途</td>
              <td width="40" align="center">记录数</td>
              <td width="40" align="center">已使用大小</td>
              <td width="80" align="center">创建时间</td>
              <td width="80" align="center">碎片</td>
              <td width="80" align="center">表引擎</td>
              <td width="80" align="center">备份状态</td>
            </tr>
          </thead>
          <tbody>
            <?php if(is_array($lists)): $i = 0; $__LIST__ = $lists;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr>
              <td align="center">
                <input class="ids" checked="chedked" type="checkbox" name="tables[]" value="<?php echo ($vo["name"]); ?>">
              </td>
              <td align="center"><?php echo ($vo["name"]); ?></td>
              <td align="center"><?php echo ($vo["comment"]); ?></td>
              <td align="center"><?php echo ($vo["rows"]); ?></td>
              <td align="center"><?php echo ($vo["size"]); ?></td>
              <td align="center"><?php echo ($vo["create_time"]); ?></td>
              <td align="center"><?php echo ($vo["data_free"]); ?></td>
              <td align="center"><?php echo ($vo["engine"]); ?></td>
              <td align="center" class="info">未备份</td>
            </tr><?php endforeach; endif; else: echo "" ;endif; ?>
          </tbody>
        </table>
        <!-- <div class="p10"><div class="pages"> <?php echo ($Page); ?> </div> </div> -->

      </div>
      <div class="btn_wrap">
        <div class="btn_wrap_pd">
          <button class="btn btn_submit mr10" id="J_ajax_export" type="button">开始备份</button>
          <button data="<?php echo U('optimize');?>" class="btn btn_submit mr10" id="J_ajax_optimize" type="button">优化表</button>
          <button data="<?php echo U('repair');?>" class="btn btn_submit mr10" id="J_ajax_repair" type="button">修复表</button>
          <button data="<?php echo U('delBackupLock');?>" class="btn btn_submit mr10" id="J_ajax_del" type="button">清除正在执行的备份任务</button>
          <div style="float:right;font-size: 16px;font-weight: bold;
  font-family: Microsoft YaHei,tahoma,arial,'Hiragino Sans GB','\5b8b\4f53',sans-serif;text-align: center;height:32px;line-height:32px;color:#666;">数据库中共有<?php echo ($tables); ?>张表，共计<?php echo ($total); ?></div>
        </div>
      </div>
    </form>

</div>
<script type="text/javascript">
(function($){
  var $form = $('#export-form');
  var $export = $("#J_ajax_export");
  var $optimize = $("#J_ajax_optimize");
  var $repair = $("#J_ajax_repair");
  var $del = $("#J_ajax_del");
  //全选的实现
  $(".check-all").click(function(){
    $(".ids").prop("checked", this.checked);
  });
  $optimize.add($repair).add($del).click(function(){
      $.post($(this).attr('data'), $form.serialize(), function(data){
          if(data.status){
              ITENY.alert('提示',data.info,1,'3000');
          } else {
              ITENY.alert('提示',data.info,2,'3000');
          }
          setTimeout(function(){
            $('#top-alert').find('button').click();
            $(that).removeClass('disabled').prop('disabled',false);
        },1500);
      }, "json");
      return false;
  });
  $export.click(function(){
      $export.parent().children().addClass("disabled");
      $export.html("正在发送备份请求...");
      $.post(
          $form.attr("action"),
          $form.serialize(),
          function(data){
              if(data.status){
                  tables = data.tables;
                  $export.html(data.info + "开始备份，请不要关闭本页面！");
                  backup(data.tab);
                  window.onbeforeunload = function(){ return "正在备份数据库，请不要关闭！" }
              } else {
                  ITENY.alert('提示',data.info,2,'3000');
                  $export.parent().children().removeClass("disabled");
                  $export.html("立即备份");
                  setTimeout(function(){
                    $('#top-alert').find('button').click();
                    $(that).removeClass('disabled').prop('disabled',false);
                },1500);
              }
          },
          "json"
      );
      return false;
  });
  function backup(tab, status){
      status && showmsg(tab.id, "开始备份...(0%)");
      $.get($form.attr("action"), tab, function(data){
          if(data.status){
              showmsg(tab.id, data.info);
              // alert(data.info);

              if(!$.isPlainObject(data.tab)){
                  $export.parent().children().removeClass("disabled");
                  $export.html("备份完成，点击重新备份");
                  window.onbeforeunload = function(){ return null }
                  return;
              }
              backup(data.tab, tab.id != data.tab.id);
          } else {
              ITENY.alert('提示',data.info,2,'3000');
              $export.parent().children().removeClass("disabled");
              $export.html("立即备份");
              setTimeout(function(){
                $('#top-alert').find('button').click();
                $(that).removeClass('disabled').prop('disabled',false);
            },1500);
          }
      }, "json");

  }

  function showmsg(id, msg){
      $form.find("input[value=" + tables[id] + "]").closest("tr").find(".info").html(msg);
  }
})(jQuery);

</script>
</body>
</html>